package com.atguigu.demo;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Ticket implements Runnable {
    private int ticket = 100;
//    ExecutorService threadpool = Executors.newFixedThreadPool(5);

    public void run() {

        synchronized (this) {
            while (ticket > 0) {
                System.out.println(Thread.currentThread().getName() + "开始售票");
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                ticket--;
                System.out.println(Thread.currentThread().getName() + "售票完成,还剩" + ticket + "张票");
            }
        }
    }
}
